package com.zyit.util;

import java.util.List;

public class Page<T> {
    private Integer pageSize = 6; //每一页显示的个数
    private Integer total; //总记录数
    private Integer start; //起始位置
    private Integer totalPage; //总页数
    private Integer pageNo; //当前页
    private List<T> pageList; //每页显示的数据集合

    /**
     *
     * @param pageNo 当前页
     * @param total 总的记录数
     */
    public Page(Integer pageNo,Integer total) {
        this.pageNo = pageNo;
        this.total = total;
        setTotalPage();
        setStart();
    }

    /**
     *
     * @param pageNo 当前页数
     * @param total 表中所有的记录数
     * @param pageSize 每页显示的记录数
     */
    public Page(Integer pageNo,Integer total,Integer pageSize) {
        this.pageNo = pageNo;
        this.total = total;
        this.pageSize = pageSize;
        setTotalPage();
        setStart();
    }

    /**
     * 获取
     * @return pageSize
     */
    public Integer getPageSize() {
        return pageSize;
    }

    /**
     * 设置
     * @param pageSize
     */
    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * 获取
     * @return total
     */
    public Integer getTotal() {
        return total;
    }

    /**
     * 设置
     * @param total
     */
    public void setTotal(Integer total) {
        this.total = total;
    }

    /**
     * 获取
     * @return start
     */
    public Integer getStart() {
        return start;
    }

    /**
     * 设置
     * @param
     * */
    public void setStart() {
        if (this.pageNo <=0){
            this.pageNo = 1;
        }
        if (this.pageNo > this.totalPage){
            this.pageNo = this.totalPage;
        }
        this.start = (pageNo - 1)*pageSize;
    }

    /**
     * 获取
     * @return totalPage
     */
    public Integer getTotalPage() {
        return totalPage;
    }

    /**
     * 设置
     * @param
     */
    public void setTotalPage() {
        this.totalPage= this.total/this.pageSize;
        if (this.total % this.pageSize !=0){
            this.totalPage+=1;
        }
    }

    /**
     * 获取
     * @return pageNo
     */
    public Integer getPageNo() {
        return pageNo;
    }

    /**
     * 设置
     * @param pageNo
     */
    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    /**
     * 获取
     * @return pageList
     */
    public List<T> getPageList() {
        return pageList;
    }

    /**
     * 设置
     * @param pageList
     */
    public void setPageList(List<T> pageList) {
        this.pageList = pageList;
    }

    public String toString() {
        return "Page{pageSize = " + pageSize + ", total = " + total + ", start = " + start + ", totalPage = " + totalPage + ", pageNo = " + pageNo + ", pageList = " + pageList + "}";
    }
}
